#!/bin/sh

if [ -n "$1" ] ;then
    src_dir=$1 
else
	echo error with source dir
	exit 1
fi

if [ -n "$2" ] ;then
    install_ext_dir=/$2
else
    install_ext_dir=
fi

echo build cmake "$src_dir"

rm linux-build-$src_dir/CMakeCache.txt

cmake 	-B linux-build-$src_dir \
		-DYATE_PREFIX_PATH=/mnt/c/install/linux \
		-DCMAKE_PREFIX_PATH=/mnt/c/install/linux \
		-DCMAKE_INSTALL_PREFIX=/mnt/c/install/linux$install_ext_dir \
		$src_dir

if [ $? -ne 0 ];then
	echo cmake $src_dir error
	exit 1
fi

cmake --build linux-build-$src_dir  -j10

if [ $? -ne 0 ];then
	echo build $src_dir error
	exit 1
fi

cmake --install linux-build-$src_dir

if [ $? -ne 0 ];then
	echo install $src_dir error
	exit 1
fi

exit 0

